<template>
  <!--登陆容器-->
  <div class="login_container">
    <!--登陆区-->
    <div class="login_box">
      <!--头像-->
      <div class="avater_box">
        <img src="https://moster0506.oss-cn-shanghai.aliyuncs.com/2020/05/15/1262504573984f37b7ea100ae3d2abc0file.png"
             alt="Logo">
      </div>
      <!--表单-->
      <div class="form_box">
        <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0" class="login_form">
          <el-form-item prop="username">
            <el-input
              prefix-icon="el-icon-user-solid"
              v-model="loginForm.username"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              prefix-icon="el-icon-lock"
              v-model="loginForm.password"></el-input>
          </el-form-item>
          <el-form-item prop="verifyCode">
            <div class="verifyCode_box">
              <el-input
                prefix-icon="el-icon-mobile"
                v-model="loginForm.verifyCode"></el-input>
              <img class="verify_img" src="https://s2.ax1x.com/2019/08/23/msFwut.png" alt="验证码">
            </div>
          </el-form-item>
          <el-form-item class="login_btn">
            <el-button type="primary" @click="submitForm('loginForm')">登陆</el-button>
            <el-button @click="resetForm('loginForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'Login',
    data () {
      return {
        loginForm: {
          username: '',
          password: '',
          verifyCode: ''
        },
        loginRules: {
          username: [
            {
              required: true,
              message: '请输入用户名',
              trigger: 'blur'
            },
            {
              min: 1,
              max: 20,
              message: '长度在 1 到 20 个字符',
              trigger: 'blur'
            }
          ],
          password: [
            {
              required: true,
              message: '请输入密码',
              trigger: 'blur'
            },
            {
              min: 1,
              max: 20,
              message: '长度在 1 到 20 个字符',
              trigger: 'blur'
            }
          ],
          verifyCode: [
            {
              required: true,
              message: '请输入验证码',
              trigger: 'blur'
            },
            {
              max: 5,
              message: '长度在 5 个字符',
              trigger: 'blur'
            }
          ],
        }
      }
    },
    methods: {
      submitForm (formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // 路由导航
            this.$router.push('Main')
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      resetForm (formName) {
        this.$refs[formName].resetFields()
      }
    }
  }
</script>

<style lang="less" scoped>
  .login_container {
    height: 100%;
    background-color: aquamarine;
  }

  .login_box {
    width: 450px;
    height: 380px;
    background-color: #ffffff;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    .avater_box {
      width: 130px;
      height: 130px;
      border: 1px solid #FFFFFF;
      border-radius: 50%;
      padding: 10px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      margin: -65px auto;
      background-color: #EEEEEE;

      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #EEEEEE;
      }
    }
    .login_form {
      position: absolute;
      bottom: 0;
      width: 100%;
      padding: 0px 20px;
      box-sizing: border-box;

      .verifyCode_box {
        display: flex;
        .verirfy_code {
          width: 70%;
          justify-content: left;
        }

        .verify_img {
          width: 30%;
          height: 45px;
          justify-content: flex-end;
        }
      }
    }
  }
</style>
